package com.qd.system.service.user;

import com.qd.common.sys.domain.login.LoginUser;

/**
 * 登录用户信息
 *
 * @author sjk
 */
public class UserLoginManager {
    private UserLoginManager() {

    }

    private static final ThreadLocal<LoginUser> USER_LOGIN_THREAD_LOCAL = new ThreadLocal<>();

    public static void setLoginUser(LoginUser data) {
        USER_LOGIN_THREAD_LOCAL.set(data);
    }

    public static LoginUser getLoginUser() {
        return USER_LOGIN_THREAD_LOCAL.get();
    }

    public static void clear() {
        final LoginUser loginUser = getLoginUser();
        if (null != loginUser) {
            loginUser.freeData();
        }
        USER_LOGIN_THREAD_LOCAL.remove();
    }

}
